<template>
	<view class="shangpin">
		<view class="header">
			<view class="nav" @tap="all()">全部</view>
			<view class="nav" @tap="showPicker('selector1')">
				<view>{{select}}</view>
				<image class="n_img" src="/static/images/sanjiao_03.png" mode=""></image>
			</view>
			<view class="nav" @tap="showPicker('selector2')">
				<view>{{select_}}</view>
				<image class="n_img" src="/static/images/sanjiao_03.png" mode=""></image>
			</view>
		</view>
		<view class="sp_list">
			<navigator :url="'/pages/shangpin_xq/shangpin_xq?id='+item.id+''" class="list" v-for="(item,index) in list" :key="item.id"  >
				<image class="l_img" :src="item.goodImgSrc" mode=""></image>
				<view class="title">{{item.goodName}}</view>
				<view class="jiage">
					<view class="money">
						<image class="coin" src="../../static/images/coin.png" mode=""></image>
						<view class="">
							{{item.goodNowPrice}}
						</view>
						
					</view>
					<view class="xiaoliang">销量{{item.goodSaleNum}}</view>
				</view>
			</navigator>
		</view>
		
		<w-picker
			mode="selector"
			value=""
			:options="selectorList"
			@confirm="onConfirm($event,'selector1')"
			ref="selector1" 
		></w-picker>
		<w-picker
			mode="selector"
			value=""
			:options="selectorList"
			@confirm="onConfirm($event,'selector2')"
			ref="selector2" 
		></w-picker>
		
	</view>
</template>
<script>
	import wPicker from "@/components/w-picker/w-picker.vue"
	import uniLoadMore from "@/components/uni-load-more.vue" 
	export default{
		components:{
			wPicker,
			uniLoadMore
		},
		data(){
			return{
				select:"销量",
				select_:"价格",
				select_x:0,
				select_p:0,
				selectorList:[
					{
						label:"由高到低",
						value:"1"
					},{
						label:"由低到高",
						value:"2"
					}
				],
				list:[],
				loadingType: 0,
				contentText: {
					contentdown: "上拉显示更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了"
				},
				keywords: '',
				cateid:0,
			}
		},
		onShow(){
			var userinfo=uni.getStorageSync('user');
			
		},
		onLoad(option){
			
			uni.setNavigationBarTitle({
			    title: '商品列表'
			});
			if(option){
				this.keywords  = option.key;
				this.cateid=option.typeid;
			}
			this.goodslist(this.select_x,this.select_p);
		},
		methods:{
			showPicker(type){
				this.$refs[type].show();
			},
			onConfirm(res,type){
				this.result=res;
				switch (type) {
					case "selector1":
						this.select=res.result;
						this.select_x = res.value;
						this.goodslist(this.select_x,this.select_p);
						break;
					case "selector2":
						 this.select_=res.result;
						 this.select_p = res.value;
						 this.goodslist(this.select_x,this.select_p);
						 break;
				} 
				console.log(res)
			},
			all(){
				this.select_x=0,
				this.select_p=0,
				this.select ="销量",
				this.select_ ="价格",
				this.keywords  = '',
				this.goodslist(this.select_x,this.select_p);
			},
			//分类下商品请求
			goodslist(x,p){
				var that=this;
				this.$http.get('mall/getGoodList',{
					x:x,
					p:p,
					keyword:this.keywords,
					cateid:this.cateid
				}).
				then(function (response) {
					if(response.code==1){
						that.list = response.data;
					}
				}).catch(function (error) {
					console.log(error);
				});
			},
		},
		//加载更多
		onReachBottom() {
			// console.log('ReachBottom');
			// if (this.loadingType !== 0) {
			// 	return;
			// }
			// this.loadingType = 1;
			// //延迟是为了看效果，实际数据时不要延迟 loadingType=2时表示没有数据了
			// // setTimeout(() => {
			// // 	this.loadingType = 0;
			// // }, 2000);
			// uni.request({
			// 	url:this.weburl+'&c=shouye&a=typegoods',
			// 	method:'GET',
			// 	header: {
			// 		'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
			// 	},
			// 	data:{
			// 		x:this.select_x,
			// 		p:this.select_p,
			// 		limit:this.list.length,
			// 		keywords:this.keywords,
			// 	},
			// 	success: (res) => {
			// 		if(res.data.code==1){
			// 			var data = res.data.data;
			// 			if(!data.length){
			// 				this.loadingType=2
			// 				return;
			// 			}
			// 			for(var i=0 ; i<data.length; i++){
			// 				this.list.push(data[i])
			// 			}
			// 		}
			// 		this.loadingType=0
			// 	},

			// })
			
		}
	}
</script>
<style>
	page{
		background-color: #f7f7f7;
	}
</style>
<style scoped lang="scss">
	.shangpin{
		width: 100%;
		.header{
			position: fixed;
			height: 110rpx;
			width: 100%;
			top: (var(--window-top) +0rpx);
			left: 0;
			align-items: center;
			background-color: #FFFFFF;
			z-index: 5;
			justify-content: space-around;
			display: flex;
			border-bottom: 1px solid #f7f7f7;
			.nav{
				display: flex;
				height: 110rpx;
				color: #5c5c5c;
				align-items: center;
				font-size: 30rpx;
				.n_img{
					margin-left: 10rpx;
					width: 28rpx;
					height: 14rpx;
				}
			}
		}
		.sp_list{
			position: relative;
			top: 130rpx;
			padding: 0 20rpx;
			display: flex;
			flex-wrap: wrap;
			.list{
				position: relative;
				width: 345rpx;
				text-align: center;
				background-color: #FFFFFF;
				margin-right: 20rpx;
				margin-bottom: 20rpx;
				&:nth-child(2n){
					margin-right: 0;
				}
				.l_img{
					width: 345rpx;
					height: 310rpx;
					border-radius: 3px 3px 0 0;
				}
				.title{
					line-height: 60rpx;
					padding: 0 20rpx;
					color: #000000;
					font-size: 30rpx;
					text-align:justify;
					width: 345rpx;
					white-space: nowrap;
					text-overflow: ellipsis; 
					overflow : hidden;
					box-sizing: border-box;
				}
				.jiage{
					width: 100%;
					height: 60rpx;
					align-items: center;
					box-sizing: border-box;
					padding: 0 20rpx;
					display: flex;
					justify-content: space-between;
					.coin{
						width:50rpx;
						height:50rpx;
					}
					.money{
						color: #102d57;
						color: 28rpx;
						display: flex;
						.text{
							font-size: 28rpx;
						}
					}
					.xiaoliang{
						color: #a5a5a5;
						font-size: 26rpx;
					}
				}
			}
		}
	}
</style>